/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.transitions.ITween;

import fever.display.effects.MSTweenStrategy;
import fever.display.effects.TweenStrategy;

/**
 * Defines tweens implementation to use to play with tween fetaure.
 * 
 * <p>Uses {@code #setTweenEngine()} method to switch/define tween engine 
 * to use.
 * 
 * <p>Available engines are
 * <ul>
 *   <li>Pixlib MS Tween ( @code fever.display.effects.MSTweenStrategy} )</li>
 *   <li>Pixlib FSP Tween ( @code fever.display.effects.FPSTweenStrategy} )</li>
 *   <li>Kairos RT Tween ( @code fever.display.effects.RTTweenStrategy} )</li>
 * </ul>
 * 
 * @author Romain Ecarnot
 */
class fever.display.effects.TweenEngine
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private static var _instance : TweenEngine;
	
	private var _strategy : TweenStrategy;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Returns {@link TweenEngine} instance.
	 */
	public static function getInstance() : TweenEngine
	{
		if( !_instance ) _instance = new TweenEngine();
		return _instance;	
	}
	
	/**
	 * Defines tween stategy to use.
	 * 
	 * @param engine TweenStrategy Tween strategy implementation
	 */
	public function setTweenEngine( engine : TweenStrategy ) : Void
	{
		if( engine ) _strategy = engine;
	}
	
	/**
	 * Returns tween strategy currently used.
	 * 
	 * @return TweenStrategy instance
	 */
	public function getTweenEngine( ) : TweenStrategy
	{
		return _strategy;
	}
	
	/**
	 * Creates and returns basic tween using defined stategy in singleton.
	 * 
	 * <p>Uses {@code #setTweenEngine()} method to switch/define tween engine 
	 * to use.
	 * 
	 * @param t 	Object which the Tween targets.
	 * @param p 	Setter (method or property).
	 * @param e 	Ending value of property.
	 * @param n 	Length of time of the motion in milliseconds.
	 * @param s 	(optional) Starting value of property.
	 * @param e 	(optional) Easing function.
	 */
	public function getBasicTween(	t, 
									p, 
									e : Number, 
									n : Number, 
									s : Number, 
									f : Function ) : ITween
	{
		return _strategy.createBasicTween( t, p, e, n, s, f );
	}
	
	/**
	 * Creates and returns multi tween using defined stategy in singleton.
	 * 
	 * <p>Uses {@code #setTweenEngine()} method to switch/define tween engine 
	 * to use.
	 * 
	 * @param p 	Object which the Tween targets.
	 * @param p 	Setter (method or property).
	 * @param e 	Ending value of property.
	 * @param n 	Length of time of the motion in milliseconds.
	 * @param s 	(optional) Starting value of property.
	 * @param f 	(optional) Easing function.
	 */
	public function getMultiTween(	t,
									p, 
									e : Array, 
									n : Number, 
									s : Array, 
									f : Function ) : ITween
	{
		return _strategy.createMultiTween( t, p, e, n, s, f );
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	private function TweenEngine()
	{
		_strategy = MSTweenStrategy.getInstance();
	}	
}